{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_problems:"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. toctree::\n",
    "   :hidden:\n",
    "   :maxdepth: 1\n",
    "   \n",
    "   custom.ipynb\n",
    "   gradients.ipynb\n",
    "   parallelization.ipynb\n",
    "\n",
    "   single/ackley.ipynb\n",
    "   single/griewank.ipynb\n",
    "   single/zakharov.ipynb\n",
    "   single/rastrigin.ipynb\n",
    "   single/rosenbrock.ipynb\n",
    "   \n",
    "   multi/bnh.ipynb\n",
    "   multi/zdt.ipynb\n",
    "   multi/osy.ipynb\n",
    "   multi/tnk.ipynb\n",
    "   multi/truss2d.ipynb\n",
    "   multi/welded_beam.ipynb\n",
    "   \n",
    "   many/dtlz.ipynb\n",
    "   \n",
    "   constrained/mw.ipynb\n",
    "   constrained/dascmop.ipynb\n",
    "   \n",
    "   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Problems"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_custom_problem:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### User-defined Problems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Problems have to be defined and some information have to be provided.\n",
    "In contrast to other frameworks we do not share the opinion of just defining a problem by a function.\n",
    "In `pymoo` the problem is defined by a class which also contains some meta data, such as the number of objectives, constraints, lower and upper bounds in the design space and so on."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Some important parameters for defining a problem are:\n",
    "\n",
    "- `n_var`: Integer value representing the number of design variables\n",
    "- `n_obj`: Integer value representing the number of objectives\n",
    "- `n_constr`: Integer value representing the number of constraints\n",
    "- `xl`: Integer or `np.ndarray` of length `n_var` representing the lower bounds of the design variables.\n",
    "- `xu`: Integer or `np.ndarray` of length `n_var` representing the upper bounds of the design variables.\n",
    "\n",
    "\n",
    "These attributes are supposed to be defined in the constructor and thus by overriding the `__init__` method."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The actual function evaluation takes place in the `_evaluate` method which has to purpose to fill the `out` dictionary with the corresponding evaluation data. The function values are supposed to be written into `out[\"F\"]`  \n",
    "and the constraints into `out[\"G\"]`  if `n_constr` is greater than zero. \n",
    "\n",
    "The example below shows a modified **Sphere** function with a radial constraint located at the center. The problem consists of 10 design variables, one objective, one constraint and the lower and upper bounds of each variable are in the range of 0 and 1. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from pymoo.model.problem import Problem\n",
    "\n",
    "\n",
    "class SphereWithConstraint(Problem):\n",
    "\n",
    "    def __init__(self):\n",
    "        super().__init__(n_var=10, n_obj=1, n_constr=1, xl=-0, xu=1)\n",
    "\n",
    "    def _evaluate(self, x, out, *args, **kwargs):\n",
    "        out[\"F\"] = np.sum((x - 0.5) ** 2, axis=1)\n",
    "        out[\"G\"] = 0.1 - out[\"F\"]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Moreover, we also provide an interface to define a problem by a function. More information about problem definitions are available [here](custom.ipynb)."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_test_problems:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Test Problems\n",
    "\n",
    "In the future we are planning to provide a comprehensive overview of problems. So far we have managed to describe a view of them and plot the functions. Please note, that we have used for some problems the descriptions from [here](https://www.sfu.ca/~ssurjano/).\n",
    "\n",
    "We would like to keep the function definitions as error free as possible and matching with the implementation. If you find any deviation please let us know.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Many-Objective"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "|Problem|Description|\n",
    "|-|-|\n",
    "|[DTLZ1](many/dtlz.ipynb#dtlz1)||\n",
    "|[DTLZ2](many/dtlz.ipynb#dtlz2)||\n",
    "|[DTLZ3](many/dtlz.ipynb#dtlz3)||\n",
    "|[DTLZ4](many/dtlz.ipynb#dtlz4)||\n",
    "|[DTLZ5](many/dtlz.ipynb#dtlz5)||\n",
    "|[DTLZ6](many/dtlz.ipynb#dtlz6)||\n",
    "|[DTLZ7](many/dtlz.ipynb#dtlz7)||\n",
    "|DTLZ1^-1||\n",
    "|Scaled DTLZ||\n",
    "|Convex DTLZ||"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Multi-Objective"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "|Problem|Variables|Objectives|Constraints|Description\n",
    "|:---|:---|:---|:---|:---|\n",
    "|[BNH](multi/bnh.ipynb)|2|2|2||\n",
    "|Carside|7|3|10||\n",
    "|Kursawe|3|2|&nbsp;||\n",
    "|[OSY](multi/osy.ipynb)|6|2|6||\n",
    "|[TNK](multi/tnk.ipynb)|2|2|2||\n",
    "|[Truss2D](multi/truss2d.ipynb)|3|2|1||\n",
    "|[Welded Beam](multi/welded_beam.ipynb)|4|2|4||\n",
    "|CTP1|2|2|(s)||\n",
    "|CTP2|2|2|(s)||\n",
    "|CTP3|2|2|(s)||\n",
    "|CTP4|2|2|(s)||\n",
    "|CTP5|2|2|(s)||\n",
    "|CTP6|2|2|(s)||\n",
    "|CTP7|2|2|(s)||\n",
    "|CTP8|2|2|(s)||\n",
    "|[ZDT1](multi/zdt.ipynb#zdt1)|30|2|&nbsp;||\n",
    "|[ZDT2](multi/zdt.ipynb#zdt2)|30|2|&nbsp;||\n",
    "|[ZDT3](multi/zdt.ipynb#zdt3)|30|2|&nbsp;||\n",
    "|[ZDT4](multi/zdt.ipynb#zdt4)|10|2|&nbsp;||\n",
    "|[ZDT5](multi/zdt.ipynb#zdt5)|80|2|&nbsp;||\n",
    "|[ZDT6](multi/zdt.ipynb#zdt6)|10|2|&nbsp;||\n",
    "|[DASCMOP1](constrained/dascmop.ipynb)|30|2|11||\n",
    "|[DASCMOP2](constrained/dascmop.ipynb)|30|2|11||\n",
    "|[DASCMOP3](constrained/dascmop.ipynb)|30|2|11||\n",
    "|[DASCMOP4](constrained/dascmop.ipynb)|30|2|11||\n",
    "|[DASCMOP5](constrained/dascmop.ipynb)|30|2|11||\n",
    "|[DASCMOP6](constrained/dascmop.ipynb)|30|2|11||\n",
    "|[DASCMOP7](constrained/dascmop.ipynb)|30|3|7||\n",
    "|[DASCMOP8](constrained/dascmop.ipynb)|30|3|7||\n",
    "|[DASCMOP9](constrained/dascmop.ipynb)|30|3|7||\n",
    "|[MW1](constrained/mw.ipynb)|15|2|1||\n",
    "|[MW2](constrained/mw.ipynb)|15|2|1||\n",
    "|[MW3](constrained/mw.ipynb)|15|2|2||\n",
    "|[MW4](constrained/mw.ipynb)|15|3|1||\n",
    "|[MW5](constrained/mw.ipynb)|15|2|3||\n",
    "|[MW6](constrained/mw.ipynb)|15|2|1||\n",
    "|[MW7](constrained/mw.ipynb)|15|2|2||\n",
    "|[MW8](constrained/mw.ipynb)|15|3|1||\n",
    "|[MW9](constrained/mw.ipynb)|15|2|1||\n",
    "|[MW10](constrained/mw.ipynb)|15|2|3||\n",
    "|[MW11](constrained/mw.ipynb)|15|2|4||\n",
    "|[MW12](constrained/mw.ipynb)|15|2|2||\n",
    "|[MW13](constrained/mw.ipynb)|15|2|2||\n",
    "|[MW14](constrained/mw.ipynb)|15|3|1||"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Single-Objective"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "|Problem|Variables|Constraints|Type|\n",
    "|-|-|-|-|\n",
    "|[Ackley](single/ackley.ipynb)|s|&nbsp;||\n",
    "|Cantilevered Beams|4|2||\n",
    "|[Griewank](single/griewank.ipynb)|s|&nbsp;||\n",
    "|Himmelblau|2|&nbsp;||\n",
    "|Knapsack|s|1||\n",
    "|Pressure Vessel|4|4||\n",
    "|[Rastrigin](single/rastrigin.ipynb)|s|&nbsp;||\n",
    "|[Rosenbrock](single/rosenbrock.ipynb)|s|&nbsp;||\n",
    "|Schwefel|s|&nbsp;||\n",
    "|Sphere|s|&nbsp;||\n",
    "|[Zakharov](single/zakharov.ipynb)|s|&nbsp;||\n",
    "|G01|13|9||\n",
    "|G02|20|2||\n",
    "|G03|10|1||\n",
    "|G04|5|6||\n",
    "|G05|4|5||\n",
    "|G06|2|2||\n",
    "|G07|10|8||\n",
    "|G08|2|2||\n",
    "|G09|8|6||\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Global Optimization** \n",
    "\n",
    "Implementations are taken from (SciPy)[https://github.com/scipy/scipy/tree/master/benchmarks/benchmarks/go_benchmark_functions] where a variety of global optimization benchmark problems are provided. Pymoo uses a wrapper class to make all those functions available. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "|Problem|Variables|Constraints|Name|\n",
    "|-|-|-|-|\n",
    "|AMGM|2||\"go-amgm\"|\n",
    "|Ackley01|2||\"go-ackley01\"|\n",
    "|Ackley02|2||\"go-ackley02\"|\n",
    "|Ackley03|2||\"go-ackley03\"|\n",
    "|Adjiman|2||\"go-adjiman\"|\n",
    "|Alpine01|2||\"go-alpine01\"|\n",
    "|Alpine02|2||\"go-alpine02\"|\n",
    "|BartelsConn|2||\"go-bartelsconn\"|\n",
    "|Beale|2||\"go-beale\"|\n",
    "|BiggsExp02|2||\"go-biggsexp02\"|\n",
    "|BiggsExp03|3||\"go-biggsexp03\"|\n",
    "|BiggsExp04|4||\"go-biggsexp04\"|\n",
    "|BiggsExp05|5||\"go-biggsexp05\"|\n",
    "|Bird|2||\"go-bird\"|\n",
    "|Bohachevsky1|2||\"go-bohachevsky1\"|\n",
    "|Bohachevsky2|2||\"go-bohachevsky2\"|\n",
    "|Bohachevsky3|2||\"go-bohachevsky3\"|\n",
    "|BoxBetts|3||\"go-boxbetts\"|\n",
    "|Branin01|2||\"go-branin01\"|\n",
    "|Branin02|2||\"go-branin02\"|\n",
    "|Brent|2||\"go-brent\"|\n",
    "|Brown|2||\"go-brown\"|\n",
    "|Bukin02|2||\"go-bukin02\"|\n",
    "|Bukin04|2||\"go-bukin04\"|\n",
    "|Bukin06|2||\"go-bukin06\"|\n",
    "|CarromTable|2||\"go-carromtable\"|\n",
    "|Chichinadze|2||\"go-chichinadze\"|\n",
    "|Cigar|2||\"go-cigar\"|\n",
    "|Cola|17||\"go-cola\"|\n",
    "|Colville|4||\"go-colville\"|\n",
    "|Corana|4||\"go-corana\"|\n",
    "|CosineMixture|2||\"go-cosinemixture\"|\n",
    "|CrossInTray|2||\"go-crossintray\"|\n",
    "|CrossLegTable|2||\"go-crosslegtable\"|\n",
    "|CrownedCross|2||\"go-crownedcross\"|\n",
    "|Csendes|2||\"go-csendes\"|\n",
    "|Cube|2||\"go-cube\"|\n",
    "|Damavandi|2||\"go-damavandi\"|\n",
    "|DeVilliersGlasser01|4||\"go-devilliersglasser01\"|\n",
    "|DeVilliersGlasser02|5||\"go-devilliersglasser02\"|\n",
    "|Deb01|2||\"go-deb01\"|\n",
    "|Deb03|2||\"go-deb03\"|\n",
    "|Decanomial|2||\"go-decanomial\"|\n",
    "|Deceptive|2||\"go-deceptive\"|\n",
    "|DeckkersAarts|2||\"go-deckkersaarts\"|\n",
    "|DeflectedCorrugatedSpring|2||\"go-deflectedcorrugatedspring\"|\n",
    "|DixonPrice|2||\"go-dixonprice\"|\n",
    "|Dolan|5||\"go-dolan\"|\n",
    "|DropWave|2||\"go-dropwave\"|\n",
    "|Easom|2||\"go-easom\"|\n",
    "|Eckerle4|3||\"go-eckerle4\"|\n",
    "|EggCrate|2||\"go-eggcrate\"|\n",
    "|EggHolder|2||\"go-eggholder\"|\n",
    "|ElAttarVidyasagarDutta|2||\"go-elattarvidyasagardutta\"|\n",
    "|Exp2|2||\"go-exp2\"|\n",
    "|Exponential|2||\"go-exponential\"|\n",
    "|FreudensteinRoth|2||\"go-freudensteinroth\"|\n",
    "|Gear|4||\"go-gear\"|\n",
    "|Giunta|2||\"go-giunta\"|\n",
    "|GoldsteinPrice|2||\"go-goldsteinprice\"|\n",
    "|Griewank|2||\"go-griewank\"|\n",
    "|Gulf|3||\"go-gulf\"|\n",
    "|Hansen|2||\"go-hansen\"|\n",
    "|Hartmann3|3||\"go-hartmann3\"|\n",
    "|Hartmann6|6||\"go-hartmann6\"|\n",
    "|HelicalValley|3||\"go-helicalvalley\"|\n",
    "|HimmelBlau|2||\"go-himmelblau\"|\n",
    "|HolderTable|2||\"go-holdertable\"|\n",
    "|Hosaki|2||\"go-hosaki\"|\n",
    "|Infinity|2||\"go-infinity\"|\n",
    "|JennrichSampson|2||\"go-jennrichsampson\"|\n",
    "|Judge|2||\"go-judge\"|\n",
    "|Katsuura|2||\"go-katsuura\"|\n",
    "|Keane|2||\"go-keane\"|\n",
    "|Kowalik|4||\"go-kowalik\"|\n",
    "|Langermann|2||\"go-langermann\"|\n",
    "|LennardJones|6||\"go-lennardjones\"|\n",
    "|Leon|2||\"go-leon\"|\n",
    "|Levy03|2||\"go-levy03\"|\n",
    "|Levy05|2||\"go-levy05\"|\n",
    "|Levy13|2||\"go-levy13\"|\n",
    "|Matyas|2||\"go-matyas\"|\n",
    "|McCormick|2||\"go-mccormick\"|\n",
    "|Meyer|3||\"go-meyer\"|\n",
    "|Michalewicz|2||\"go-michalewicz\"|\n",
    "|MieleCantrell|4||\"go-mielecantrell\"|\n",
    "|Mishra01|2||\"go-mishra01\"|\n",
    "|Mishra02|2||\"go-mishra02\"|\n",
    "|Mishra03|2||\"go-mishra03\"|\n",
    "|Mishra04|2||\"go-mishra04\"|\n",
    "|Mishra05|2||\"go-mishra05\"|\n",
    "|Mishra06|2||\"go-mishra06\"|\n",
    "|Mishra07|2||\"go-mishra07\"|\n",
    "|Mishra08|2||\"go-mishra08\"|\n",
    "|Mishra09|3||\"go-mishra09\"|\n",
    "|Mishra10|2||\"go-mishra10\"|\n",
    "|Mishra11|2||\"go-mishra11\"|\n",
    "|MultiModal|2||\"go-multimodal\"|\n",
    "|NeedleEye|2||\"go-needleeye\"|\n",
    "|NewFunction01|2||\"go-newfunction01\"|\n",
    "|NewFunction02|2||\"go-newfunction02\"|\n",
    "|OddSquare|2||\"go-oddsquare\"|\n",
    "|Parsopoulos|2||\"go-parsopoulos\"|\n",
    "|Pathological|2||\"go-pathological\"|\n",
    "|Paviani|10||\"go-paviani\"|\n",
    "|PenHolder|2||\"go-penholder\"|\n",
    "|Penalty01|2||\"go-penalty01\"|\n",
    "|Penalty02|2||\"go-penalty02\"|\n",
    "|PermFunction01|2||\"go-permfunction01\"|\n",
    "|PermFunction02|2||\"go-permfunction02\"|\n",
    "|Pinter|2||\"go-pinter\"|\n",
    "|Plateau|2||\"go-plateau\"|\n",
    "|Powell|4||\"go-powell\"|\n",
    "|PowerSum|4||\"go-powersum\"|\n",
    "|Price01|2||\"go-price01\"|\n",
    "|Price02|2||\"go-price02\"|\n",
    "|Price03|2||\"go-price03\"|\n",
    "|Price04|2||\"go-price04\"|\n",
    "|Qing|2||\"go-qing\"|\n",
    "|Quadratic|2||\"go-quadratic\"|\n",
    "|Quintic|2||\"go-quintic\"|\n",
    "|Rana|2||\"go-rana\"|\n",
    "|Rastrigin|2||\"go-rastrigin\"|\n",
    "|Ratkowsky01|4||\"go-ratkowsky01\"|\n",
    "|Ratkowsky02|3||\"go-ratkowsky02\"|\n",
    "|Ripple01|2||\"go-ripple01\"|\n",
    "|Ripple25|2||\"go-ripple25\"|\n",
    "|Rosenbrock|2||\"go-rosenbrock\"|\n",
    "|RosenbrockModified|2||\"go-rosenbrockmodified\"|\n",
    "|RotatedEllipse01|2||\"go-rotatedellipse01\"|\n",
    "|RotatedEllipse02|2||\"go-rotatedellipse02\"|\n",
    "|Salomon|2||\"go-salomon\"|\n",
    "|Sargan|2||\"go-sargan\"|\n",
    "|Schaffer01|2||\"go-schaffer01\"|\n",
    "|Schaffer02|2||\"go-schaffer02\"|\n",
    "|Schaffer03|2||\"go-schaffer03\"|\n",
    "|Schaffer04|2||\"go-schaffer04\"|\n",
    "|Schwefel01|2||\"go-schwefel01\"|\n",
    "|Schwefel02|2||\"go-schwefel02\"|\n",
    "|Schwefel04|2||\"go-schwefel04\"|\n",
    "|Schwefel06|2||\"go-schwefel06\"|\n",
    "|Schwefel20|2||\"go-schwefel20\"|\n",
    "|Schwefel21|2||\"go-schwefel21\"|\n",
    "|Schwefel22|2||\"go-schwefel22\"|\n",
    "|Schwefel26|2||\"go-schwefel26\"|\n",
    "|Schwefel36|2||\"go-schwefel36\"|\n",
    "|Shekel05|4||\"go-shekel05\"|\n",
    "|Shekel07|4||\"go-shekel07\"|\n",
    "|Shekel10|4||\"go-shekel10\"|\n",
    "|Shubert01|2||\"go-shubert01\"|\n",
    "|Shubert03|2||\"go-shubert03\"|\n",
    "|Shubert04|2||\"go-shubert04\"|\n",
    "|SineEnvelope|2||\"go-sineenvelope\"|\n",
    "|SixHumpCamel|2||\"go-sixhumpcamel\"|\n",
    "|Sodp|2||\"go-sodp\"|\n",
    "|Sphere|2||\"go-sphere\"|\n",
    "|Step|2||\"go-step\"|\n",
    "|Step2|2||\"go-step2\"|\n",
    "|Stochastic|2||\"go-stochastic\"|\n",
    "|StretchedV|2||\"go-stretchedv\"|\n",
    "|StyblinskiTang|2||\"go-styblinskitang\"|\n",
    "|TestTubeHolder|2||\"go-testtubeholder\"|\n",
    "|ThreeHumpCamel|2||\"go-threehumpcamel\"|\n",
    "|Thurber|7||\"go-thurber\"|\n",
    "|Treccani|2||\"go-treccani\"|\n",
    "|Trefethen|2||\"go-trefethen\"|\n",
    "|Trid|6||\"go-trid\"|\n",
    "|Trigonometric01|2||\"go-trigonometric01\"|\n",
    "|Trigonometric02|2||\"go-trigonometric02\"|\n",
    "|Tripod|2||\"go-tripod\"|\n",
    "|Ursem01|2||\"go-ursem01\"|\n",
    "|Ursem03|2||\"go-ursem03\"|\n",
    "|Ursem04|2||\"go-ursem04\"|\n",
    "|UrsemWaves|2||\"go-ursemwaves\"|\n",
    "|VenterSobiezcczanskiSobieski|2||\"go-ventersobiezcczanskisobieski\"|\n",
    "|Vincent|2||\"go-vincent\"|\n",
    "|Watson|6||\"go-watson\"|\n",
    "|Wavy|2||\"go-wavy\"|\n",
    "|WayburnSeader01|2||\"go-wayburnseader01\"|\n",
    "|WayburnSeader02|2||\"go-wayburnseader02\"|\n",
    "|Weierstrass|2||\"go-weierstrass\"|\n",
    "|Whitley|2||\"go-whitley\"|\n",
    "|Wolfe|3||\"go-wolfe\"|\n",
    "|XinSheYang01|2||\"go-xinsheyang01\"|\n",
    "|XinSheYang02|2||\"go-xinsheyang02\"|\n",
    "|XinSheYang03|2||\"go-xinsheyang03\"|\n",
    "|XinSheYang04|2||\"go-xinsheyang04\"|\n",
    "|Xor|9||\"go-xor\"|\n",
    "|YaoLiu04|2||\"go-yaoliu04\"|\n",
    "|YaoLiu09|2||\"go-yaoliu09\"|\n",
    "|Zacharov|2||\"go-zacharov\"|\n",
    "|ZeroSum|2||\"go-zerosum\"|\n",
    "|Zettl|2||\"go-zettl\"|\n",
    "|Zimmerman|2||\"go-zimmerman\"|\n",
    "|Zirilli|2||\"go-zirilli\"|\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}